<%--
  Created by IntelliJ IDEA.
  User: hklyq
  Date: 2019-03-01
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加过户信息</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <form id="formSet1">
        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_50">
                <div class="label">过户项目</div>
                <div class="field">
                    <select name="category" id="category" validate="{required:true,select:true}">
                        <option selected value="  ">请选择</option>
                        <c:forEach items="${category}" var="item">
                            <option value="${item.key }">${item.value }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">完成时间</div>
                <div class="field">
                    <input name="emtimateTime" id="emtimateTime" type="text" class="ui-datepicker" value=""
                           validate="{required:true}">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">完成情况</div>
                <div class="field">
                    <select name="completionStatus" id="completionStatus">
                        <option value="0">进行中</option>
                        <option value="1" selected>已完成</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_50">
                <div class="label">过户金额</div>
                <div class="field">
                    <input type="text" id="amount" name="amount" class="ui-textbox" value=""/>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">备注</div>
                <div class="field">
                    <textarea name="remark" id="remark" rows="3" class="l-textarea" style="width:98%"
                              value=""></textarea>
                </div>
            </div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="sqPanel_body">
                <div id="assTransFerInfoFileCfgGrid" class="sq-grid"></div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
        </div>
    </form>
</div>


<script type="text/javascript">
    var assTransFerInfoFileCfgGrid = null;
    // 预先获取的诉讼基础信息的id
    var id = "${id}";
    // 转优车id
    var dealId = "${dealId}";

    $(function () {
        var formSet1 = $('#formSet1').ligerForm({
            validate: true
        });

        //项目资料Grid
        assTransFerInfoFileCfgGrid = $("#assTransFerInfoFileCfgGrid").ligerGrid({
            url: '<%=path%>/ass/dealcar/manage/initAssTransferInfoFileCfgGrid.do?id=' + id,
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', align: 'center', minWidth: 100, enabledSort: false},
                {
                    display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            var h;
                            h = '<a href="javascript:downloadFile(';
                            h += "'" + rowdata.filePath + "'";
                            h += ",'" + rowdata.fileNm + "'";
                            h += ')">' + rowdata.fileNm + '</a>'
                            return h;
                        }
                    }
                },
                {
                    display: '上传时间',
                    name: 'crtTm',
                    align: 'center',
                    minWidth: 100,
                    enabledSort: false,
                    render: renderDate
                },
                {
                    display: '操作', name: '', minWidth: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                        return h;
                    }
                },
                {
                    display: '上传', name: 'uploadNm', width: 80, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        h += '<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                            ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\');"></span>';
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $('#assTransFerInfoFileCfgGrid').rowspan('datNm');
                $('#assTransFerInfoFileCfgGrid').rowspan('uploadNm');
            },
        });
    });

    function downloadFile() {

    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath = "";
        filePath = "AssTransferInfo";

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            'fileParams': JSON.stringify(msg.data),
                            'id': id,
                            'cfgCd': cfgCd,
                            'cfgDtlCd': cfgDtlCd,
                            'orgCd': orgCd
                        },
                        url: '<%=path%>/ass/dealcar/manage/uploadAssTransferInfoFile.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                assTransFerInfoFileCfgGrid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    // 删除文件
    function delFile(event, _fileId) {
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if (!flag) {
                return;
            } else {
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId': _fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        if (msg.success == 1) {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                            event.stopPropagation();
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        } else {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    // 保存
    function save() {
        var form = liger.get("formSet1");
        if (!form.valid()) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
        var data = form.getData();
        var url = "<%=path%>/ass/dealcar/manage/addAssTransferInfo.do?dealId=" + dealId + "&id=" + id;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            success: function (msg) {
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    setTimeout(function () {
                        frameElement.dialog.close();
                    }, 1500);
                    parent.grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

</script>

</body>
</html>

